package com.woniuxy.amusementparkos.controller.lzw;

import com.woniuxy.amusementparkos.entity.lzw.ImprestSourceInfo;
import com.woniuxy.amusementparkos.entity.wyh.Customer;
import com.woniuxy.amusementparkos.entity.wyh.WristStrap_Info;
import com.woniuxy.amusementparkos.service.wyh.WristStrap_InfoService;
import com.woniuxy.amusementparkos.util.lzw.result.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 强制结算
 *    作用：当用户离园后，腕带被带走，并不返回办理结算手续后，当用户
 * @author lizhiwen
 * @create 2020-04-29 10:16 上午
 */
@RestController
@RequestMapping("settlement")
public class SettlementController {

    /**
     * 服务对象，腕带信息
     *    针对于：所有未结算腕带
     */
    @Resource
    WristStrap_InfoService wristStrap_infoService;

    /**
     * 获取所有未结算腕带信息
     *    实现逻辑: 状态为未结算（info_state=0）作为条件进行查询
     *
     * @return 所有未结算腕带信息
     */
    @GetMapping("listWristStrapInfoByStateIsZero")
    public ResponseResult<List<WristStrap_Info>> listWristStrapInfo(){
        // 设置状态为 未结算（info_state=0）
        WristStrap_Info wristStrap_info = new WristStrap_Info();
        wristStrap_info.setInfo_state(0);
        wristStrap_info.setCustomer(new Customer());

        ResponseResult<List<WristStrap_Info>> result = null;
        try{
            result = new ResponseResult<>(
                    200, "成功",
                   ( wristStrap_infoService.selectByCondition(wristStrap_info,1,10000)).getBeanList());
        }catch (Exception e){
            result = new ResponseResult<>(501,e.getMessage(),null);
        }
        return result;
    }

    @GetMapping("updateWristStrapInfoState")
    public ResponseResult<Integer> updateWristStrapInfoState(){
        // 设置状态为 未结算（info_state=0）
        WristStrap_Info wristStrap_info = new WristStrap_Info();
        wristStrap_info.setInfo_state(1);
        wristStrap_info.setEndtime(new Date());
        ResponseResult<Integer> result = null;
        try{
            result = new ResponseResult<>(
                    200, "成功",
                    wristStrap_infoService.updateAllWindupMessage(wristStrap_info));
        }catch (Exception e){
            result = new ResponseResult<>(501,e.getMessage(),null);
        }
        return result;
    }
}
